package main


import (
	"encoding/json"
	"fmt"
	"io/ioutil"


)



type Res struct{

	Code   int  `mapstructure:"code" json:"code"`
	Data   Data `mapstructure:"data" json:"data"`
}


type Data struct{
	Count int  		`mapstructure:"count" json:"count"`
	Info  []Info	`mapstructure:"info" json:"info"`

}

type Info struct{

	Host    Host    	`mapstructure:"host" json:"host"`
	Set     []interface{}	`mapstructure:"set" json:"set"`
	Biz     []interface{}	`mapstructure:"biz" json:"biz"`
	Module  []interface{}	`mapstructure:"module" json:"module"`
}


type Host struct {
	OsName    string  `mapstructure:"bk_os_name" json:"bk_os_name"`
}



func main(){

	b, err := ioutil.ReadFile("1.txt") // just pass the file name
	if err != nil {
		fmt.Print(err)
	}

	jsonStr := string(b) // convert content to a 'string'

	var res Res
	json.Unmarshal([]byte(jsonStr), &res)

	info := res.Data.Info
	fmt.Println(info)

	var host_info []map[string]interface{}

	for _, item := range(res.Data.Info){
		host_info = append(host_info, map[string]interface{}{
			"osname": item.Host.OsName,
			"code": res.Code,
		})
	}

	response := map[string]interface{}{

		"host_info": host_info,
	}
	return gin(response ,c)
}